package com.gerfmarquez.nymph.ui.listeners;

import android.app.AlertDialog;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;

import com.gerfmarquez.nymph.R;
import com.gerfmarquez.nymph.ui.gesture.detectors.LongPressDetector;
import com.gerfmarquez.nymph.ui.seekbar.VerticalSeekBar;

public class SeekBarOnTouchListener implements View.OnTouchListener{
	
	GestureDetector gDLongPress;
	LongPressDetector longPressDetector;
	Context context;
	private static String TAG = "SeekBarOnTouchListener";
	static Drawable prDr;
	Resources r;

	
	public SeekBarOnTouchListener(Context context) {
		longPressDetector = new LongPressDetector(context);
		gDLongPress = new GestureDetector(longPressDetector);
		this.context = context;
		r = context.getResources();
	}
		
		@Override
		public boolean onTouch(View verticalSeekBar, MotionEvent event) {
			if(gDLongPress.onTouchEvent(event)) {
				return true;
			} else {
				if(longPressDetector.isLongPressedCustom) {
					longPressDetector.isLongPressedCustom = false;
					
//					Log.d("OnTouchListenerSeekBar", "True Long press view id = "+indexChild);
					
			        CharSequence[] items = {"Add Music Note/s", "Remove Music Note/s", "Change Note Tone"};

			        AlertDialog.Builder builder = new AlertDialog.Builder(context);
			        builder.setTitle("Choose an action");
			        DialogListenerActionMusicNote dlam =  new DialogListenerActionMusicNote(context);
			        dlam.setVerticalSeekBar((VerticalSeekBar)verticalSeekBar);
			        builder.setItems(items,dlam);
			        AlertDialog alert = builder.create();
			        alert.show();
			        
//					VerticalSeekBar verticalSeekBar1 = (VerticalSeekBar)verticalSeekBar;
//					Rect bounds = verticalSeekBar1.getProgressDrawable().getBounds();
//					int progr = verticalSeekBar1.getProgress();
//					int max = verticalSeekBar1.getMax();
//					int width = verticalSeekBar1.getWidth(); 
//					int height = verticalSeekBar1.getHeight();
//					prDr = verticalSeekBar1.getProgressDrawable();
//					verticalSeekBar1.setProgressDrawable(r.getDrawable(R.drawable.myprogress));
//					verticalSeekBar1.getProgressDrawable().setBounds(bounds);
//					verticalSeekBar1.setMax(max);
//					verticalSeekBar1.setProgress(1);
//					verticalSeekBar1.setProgress(progr);
//					verticalSeekBar1.onSizeChanged(width, height);
//					verticalSeekBar1.refreshDrawableState();
			        
					return true;
				}
				else {
//					Log.d("OnTouchListenerSeekBar", "False Long PRess  view id = "+((VerticalSeekBar)verticalSeekBar).getIdVerticalSeekBar());
					return false;
				}
			}

	}
}
